# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import parse
import recup
import filtres
import re
import os
import shutil
import thread_fiches
import thread_dl
import globales
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s



class Ui_Fenetre_principale(QtCore.QObject,object):
    def setupUi(self, Fenetre_principale):
        
        self.papa = Fenetre_principale
        Fenetre_principale.setObjectName(_fromUtf8("Fenetre_principale"))
        Fenetre_principale.setWindowModality(QtCore.Qt.NonModal)
        Fenetre_principale.resize(910, 678)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Fenetre_principale.sizePolicy().hasHeightForWidth())
        Fenetre_principale.setSizePolicy(sizePolicy)
        Fenetre_principale.setFocusPolicy(QtCore.Qt.NoFocus)
        Fenetre_principale.setWindowOpacity(1.0)
        Fenetre_principale.setLayoutDirection(QtCore.Qt.LeftToRight)
        Fenetre_principale.setAutoFillBackground(True)
        Fenetre_principale.setTabShape(QtGui.QTabWidget.Rounded)
        self.centralwidget = QtGui.QWidget(Fenetre_principale)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
        self.centralwidget.setSizePolicy(sizePolicy)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.gridLayout_4 = QtGui.QGridLayout(self.centralwidget)
        self.gridLayout_4.setMargin(0)
        self.gridLayout_4.setSpacing(0)
        self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
        self.les_onglets = QtGui.QTabWidget(self.centralwidget)
        self.les_onglets.setEnabled(True)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(5)
        sizePolicy.setVerticalStretch(5)
        sizePolicy.setHeightForWidth(self.les_onglets.sizePolicy().hasHeightForWidth())
        self.les_onglets.setSizePolicy(sizePolicy)
        self.les_onglets.setMinimumSize(QtCore.QSize(0, 0))
        self.les_onglets.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.les_onglets.setAutoFillBackground(True)
        self.les_onglets.setObjectName(_fromUtf8("les_onglets"))
        self.first_page = QtGui.QWidget()
        self.first_page.setObjectName(_fromUtf8("first_page"))
        self.gridLayout_3 = QtGui.QGridLayout(self.first_page)
        self.gridLayout_3.setMargin(0)
        self.gridLayout_3.setSpacing(0)
        self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
        self.gridLayout_2 = QtGui.QGridLayout()
        self.gridLayout_2.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
        self.Titre = QtGui.QLabel(self.first_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Titre.sizePolicy().hasHeightForWidth())
        self.Titre.setSizePolicy(sizePolicy)
        self.Titre.setScaledContents(False)
        self.Titre.setAlignment(QtCore.Qt.AlignCenter)
        self.Titre.setObjectName(_fromUtf8("Titre"))
        self.gridLayout_2.addWidget(self.Titre, 0, 1, 1, 1)
        self.Synopsis = QtGui.QTextEdit(self.first_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Synopsis.sizePolicy().hasHeightForWidth())
        self.Synopsis.setSizePolicy(sizePolicy)
        self.Synopsis.setReadOnly(True)
        self.Synopsis.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        self.Synopsis.setObjectName(_fromUtf8("Synopsis"))
        self.gridLayout_2.addWidget(self.Synopsis, 5, 1, 1, 1)
        self.liste_liens = QtGui.QListWidget(self.first_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.liste_liens.sizePolicy().hasHeightForWidth())
        self.liste_liens.setSizePolicy(sizePolicy)
        self.liste_liens.setFrameShape(QtGui.QFrame.StyledPanel)
        self.liste_liens.setFrameShadow(QtGui.QFrame.Sunken)
        self.liste_liens.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
        self.liste_liens.setObjectName(_fromUtf8("liste_liens"))
        self.gridLayout_2.addWidget(self.liste_liens, 6, 1, 1, 1)
        self.download_it = QtGui.QPushButton(self.first_page)
        self.download_it.setFlat(False)
        self.download_it.setObjectName(_fromUtf8("download_it"))
        self.gridLayout_2.addWidget(self.download_it, 7, 1, 1, 1)
        self.Image = QtGui.QLabel(self.first_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Image.sizePolicy().hasHeightForWidth())
        self.Image.setSizePolicy(sizePolicy)
        self.Image.setAlignment(QtCore.Qt.AlignCenter)
        self.Image.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        self.Image.setObjectName(_fromUtf8("Image"))
        self.gridLayout_2.addWidget(self.Image, 1, 1, 2, 1)
        self.Genre = QtGui.QLabel(self.first_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Genre.sizePolicy().hasHeightForWidth())
        self.Genre.setSizePolicy(sizePolicy)
        self.Genre.setAlignment(QtCore.Qt.AlignCenter)
        self.Genre.setObjectName(_fromUtf8("Genre"))
        self.gridLayout_2.addWidget(self.Genre, 3, 1, 1, 1)
        self.Liste_animes = QtGui.QListWidget(self.first_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Liste_animes.sizePolicy().hasHeightForWidth())
        self.Liste_animes.setSizePolicy(sizePolicy)
        self.Liste_animes.setObjectName(_fromUtf8("Liste_animes"))
        self.gridLayout_2.addWidget(self.Liste_animes, 0, 0, 8, 1)
        self.gridLayout_2.setRowStretch(0, 1)
        self.gridLayout_3.addLayout(self.gridLayout_2, 0, 0, 1, 1)
        self.les_onglets.addTab(self.first_page, _fromUtf8(""))
        self.second_page = QtGui.QWidget()
        self.second_page.setObjectName(_fromUtf8("second_page"))
        self.gridLayout = QtGui.QGridLayout(self.second_page)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.gridLayout_5 = QtGui.QGridLayout()
        self.gridLayout_5.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
        self.gridLayout_5.setVerticalSpacing(6)
        self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5"))
        self.Termines = QtGui.QLabel(self.second_page)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Haettenschweiler"))
        font.setPointSize(12)
        self.Termines.setFont(font)
        self.Termines.setObjectName(_fromUtf8("Termines"))
        self.gridLayout_5.addWidget(self.Termines, 1, 1, 1, 1)
        
        self.liste_termines = QtGui.QListWidget(self.second_page)
        globales.liste_termines = self.liste_termines
        
        self.liste_termines.setObjectName(_fromUtf8("liste_termines"))
        self.gridLayout_5.addWidget(self.liste_termines, 6, 1, 1, 1)
        
        self.liste_en_attente = QtGui.QListWidget(self.second_page)
        globales.liste_en_attente = self.liste_en_attente
        
        self.liste_en_attente.setObjectName(_fromUtf8("liste_en_attente"))
        self.gridLayout_5.addWidget(self.liste_en_attente, 6, 0, 1, 1)
        
        self.avancement_en_cours = QtGui.QProgressBar(self.second_page)
        globales.avancement_en_cours = self.avancement_en_cours
                
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.avancement_en_cours.sizePolicy().hasHeightForWidth())
        self.avancement_en_cours.setSizePolicy(sizePolicy)
        self.avancement_en_cours.setProperty("value", 50)
        self.avancement_en_cours.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.avancement_en_cours.setTextVisible(True)
        self.avancement_en_cours.setTextDirection(QtGui.QProgressBar.TopToBottom)
        self.avancement_en_cours.setObjectName(_fromUtf8("avancement_en_cours"))
        self.gridLayout_5.addWidget(self.avancement_en_cours, 18, 0, 1, 2)
        
        self.taille_en_cours = QtGui.QLabel(self.second_page)
        globales.taille_en_cours = self.taille_en_cours
        
        self.taille_en_cours.setObjectName(_fromUtf8("taille_en_cours"))
        self.gridLayout_5.addWidget(self.taille_en_cours, 13, 0, 1, 1)
        
        self.titre_en_cours = QtGui.QLabel(self.second_page)
        globales.titre_en_cours = self.titre_en_cours
        
        self.titre_en_cours.setObjectName(_fromUtf8("titre_en_cours"))
        self.gridLayout_5.addWidget(self.titre_en_cours, 12, 0, 1, 1)
        self.En_cours = QtGui.QLabel(self.second_page)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Haettenschweiler"))
        font.setPointSize(12)
        self.En_cours.setFont(font)
        self.En_cours.setObjectName(_fromUtf8("En_cours"))
        self.gridLayout_5.addWidget(self.En_cours, 11, 0, 1, 1)
        self.Enattente = QtGui.QLabel(self.second_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Enattente.sizePolicy().hasHeightForWidth())
        self.Enattente.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Haettenschweiler"))
        font.setPointSize(12)
        self.Enattente.setFont(font)
        self.Enattente.setObjectName(_fromUtf8("Enattente"))
        self.gridLayout_5.addWidget(self.Enattente, 1, 0, 1, 1)
        self.monter_button = QtGui.QPushButton(self.second_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.monter_button.sizePolicy().hasHeightForWidth())
        self.monter_button.setSizePolicy(sizePolicy)
        self.monter_button.setFlat(False)
        self.monter_button.setObjectName(_fromUtf8("monter_button"))
        self.gridLayout_5.addWidget(self.monter_button, 4, 0, 1, 1)
        self.pause_button = QtGui.QPushButton(self.second_page)
        self.pause_button.setObjectName(_fromUtf8("pause_button"))
        self.gridLayout_5.addWidget(self.pause_button, 9, 0, 1, 1)
        self.descendre_button = QtGui.QPushButton(self.second_page)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.descendre_button.sizePolicy().hasHeightForWidth())
        self.descendre_button.setSizePolicy(sizePolicy)
        self.descendre_button.setObjectName(_fromUtf8("descendre_button"))
        self.gridLayout_5.addWidget(self.descendre_button, 7, 0, 1, 1)
        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
        self.gridLayout_5.addItem(spacerItem, 8, 0, 1, 1)

        self.statut_en_cours = QtGui.QLabel(self.second_page)
        globales.statut_en_cours = self.statut_en_cours
        
        self.statut_en_cours.setAlignment(QtCore.Qt.AlignCenter)
        self.statut_en_cours.setObjectName(_fromUtf8("statut_en_cours"))
        self.gridLayout_5.addWidget(self.statut_en_cours, 14, 0, 1, 2)
        self.gridLayout.addLayout(self.gridLayout_5, 0, 0, 1, 1)
        self.les_onglets.addTab(self.second_page, _fromUtf8(""))
        self.gridLayout_4.addWidget(self.les_onglets, 0, 0, 1, 1)
        Fenetre_principale.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(Fenetre_principale)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 910, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menu_Fichier = QtGui.QMenu(self.menubar)
        self.menu_Fichier.setObjectName(_fromUtf8("menu_Fichier"))
        self.menu_Edition = QtGui.QMenu(self.menubar)
        self.menu_Edition.setObjectName(_fromUtf8("menu_Edition"))
        self.menuRechercher = QtGui.QMenu(self.menu_Edition)
        self.menuRechercher.setObjectName(_fromUtf8("menuRechercher"))
        self.menu = QtGui.QMenu(self.menubar)
        self.menu.setObjectName(_fromUtf8("menu"))
        Fenetre_principale.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(Fenetre_principale)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        Fenetre_principale.setStatusBar(self.statusbar)
        self.action_R_cup_rer_la_liste = QtGui.QAction(Fenetre_principale)
        self.action_R_cup_rer_la_liste.setObjectName(_fromUtf8("action_R_cup_rer_la_liste"))
        self.action_Charger_la_liste = QtGui.QAction(Fenetre_principale)
        self.action_Charger_la_liste.setObjectName(_fromUtf8("action_Charger_la_liste"))
        self.action_Reg_n_rer_le_cache = QtGui.QAction(Fenetre_principale)
        self.action_Reg_n_rer_le_cache.setObjectName(_fromUtf8("action_Reg_n_rer_le_cache"))
        self.action_T_l_charger_les_liens = QtGui.QAction(Fenetre_principale)
        self.action_T_l_charger_les_liens.setObjectName(_fromUtf8("action_T_l_charger_les_liens"))
        self.action_A_propos = QtGui.QAction(Fenetre_principale)
        self.action_A_propos.setObjectName(_fromUtf8("action_A_propos"))
        self.actionPar_titre = QtGui.QAction(Fenetre_principale)
        self.actionPar_titre.setObjectName(_fromUtf8("actionPar_titre"))
        self.actionPar_genre = QtGui.QAction(Fenetre_principale)
        self.actionPar_genre.setObjectName(_fromUtf8("actionPar_genre"))
        self.menu_Fichier.addAction(self.action_R_cup_rer_la_liste)
        self.menu_Fichier.addAction(self.action_Charger_la_liste)
        self.menuRechercher.addAction(self.actionPar_titre)
        self.menuRechercher.addAction(self.actionPar_genre)
        self.menu_Edition.addAction(self.action_Reg_n_rer_le_cache)
        self.menu_Edition.addAction(self.menuRechercher.menuAction())
        self.menu_Edition.addAction(self.action_T_l_charger_les_liens)
        self.menu.addAction(self.action_A_propos)
        self.menubar.addAction(self.menu_Fichier.menuAction())
        self.menubar.addAction(self.menu_Edition.menuAction())
        self.menubar.addAction(self.menu.menuAction())
        self.liste_liens.setSortingEnabled(False)
        self.liste_en_attente.setSortingEnabled(False)
        

        self.retranslateUi(Fenetre_principale)
        self.les_onglets.setCurrentIndex(0)
        #Exemple de connect !
        QtCore.QObject.connect(self.download_it, QtCore.SIGNAL(_fromUtf8("clicked()")), self.telecharger_les_liens)
        QtCore.QObject.connect(self.action_R_cup_rer_la_liste, QtCore.SIGNAL(_fromUtf8("triggered()")),self.recuperer_liste)
        QtCore.QObject.connect(self.action_Charger_la_liste, QtCore.SIGNAL(_fromUtf8("triggered()")),self.charger_liste)
        QtCore.QObject.connect(self.action_Reg_n_rer_le_cache, QtCore.SIGNAL(_fromUtf8("triggered()")),self.regenerer_le_cache)
        QtCore.QObject.connect(self.action_T_l_charger_les_liens, QtCore.SIGNAL(_fromUtf8("triggered()")),self.telecharger_les_liens)
        QtCore.QObject.connect(self.action_A_propos, QtCore.SIGNAL(_fromUtf8("triggered()")),self.about)
        QtCore.QObject.connect(self.actionPar_titre, QtCore.SIGNAL(_fromUtf8("triggered()")),self.fuck)
        QtCore.QObject.connect(self.actionPar_genre, QtCore.SIGNAL(_fromUtf8("triggered()")),self.fuck)
        QtCore.QObject.connect(self.Liste_animes, QtCore.SIGNAL(_fromUtf8("currentRowChanged(int)")),self.changer_affichage)
        QtCore.QObject.connect(self.pause_button, QtCore.SIGNAL(_fromUtf8("clicked()")), self.pauser)
        QtCore.QObject.connect(self.descendre_button, QtCore.SIGNAL(_fromUtf8("clicked()")), self.descendre_dl)
        QtCore.QObject.connect(self.monter_button, QtCore.SIGNAL(_fromUtf8("clicked()")), self.monter_dl)
        self.emit(QtCore.SIGNAL("Ready(QObject)"),Fenetre_principale)
        #QtCore.QMetaObject.connectSlotsByName(Fenetre_principale)


    def pauser(self):
        if globales.pause:
            globales.pause = False
            self.pause_button.setText("Mettre en pause")
        else:
            globales.pause = True
            self.pause_button.setText("Relancer les téléchargements")

    def changer_affichage(self, row):
        global data
        global ficheInfos
        ficheInfos = parse.getFicheInfos(data[row]['fiche'])
        self.liste_liens.clear()
        for episode in ficheInfos['episodes']:
            nom = ''.join([episode['numero'], " - ", episode['encodage'], " (" +episode['resolution'],"), "+episode['taille'], " - " , episode['duree']])
            self.liste_liens.addItem(nom)
        

        for oav in ficheInfos['bonus']:
            nom = ''.join(["Bonus - ",oav['nom']," - ", oav['taille']])
            self.liste_liens.addItem(nom)

        
        self.Titre.setText(ficheInfos["titre"])
        self.Genre.setText(", ".join(ficheInfos["genres"]))
        self.Synopsis.clear()
        self.Synopsis.insertPlainText(ficheInfos["description"])
        self.Image.setPixmap(QtGui.QPixmap("img/"+ficheInfos["image"][(ficheInfos["image"].rfind('/')+1):]))

    def fuck(self):
        QtGui.QMessageBox.about(self.papa, "Bientôt", "Disponible dans la prochaine version !")
		
    def about(self):
        QtGui.QMessageBox.about(self.papa, "A propos", "http://otaku-attitude.net")

    def recuperer_liste(self):
        global data
        data = None
        recup.recupAnimes()
        self.charger_liste()

    def charger_liste(self):
        global data
        global liste_anime
        #thread_fiches.run()
        try :
            data = parse.getAnimes()
            self.Liste_animes.clear()
            for anime in data :
                self.Liste_animes.addItem(anime['nom'])
            self.Liste_animes.setCurrentRow(0)
            thread_fiches.stop()
            thread_fiches.run()
            
        except:
            data = None
            recup.recupAnimes()
            self.charger_liste()

    def prepareCaching(self):
        self.charger_liste()
        thread_fiches.run()
        
        

    def regenerer_le_cache(self):
        thread_fiches.stop()
        shutil.rmtree('img')
        shutil.rmtree('fiches')
        os.remove('animes.xml')
        recup.recupAnimes()
        thread_fiches.run()
        #action()

    def prepareAffichage(self, titre, taille):
        self.item = self.liste_en_attente.takeItem(self.liste_en_attente.count()-1)
        self.titre_en_cours.setText("Episode en téléchargement : "+titre)
        taille = taille / 1024 / 1024
        self.taille_en_cours.setText("Taille : "+ str(int(taille))+"Mo")
        self.avancement_en_cours.setValue(0)

    def modifStatut(self, statut):
        self.statut_en_cours.setText(statut)

    def defilList(self):
        self.liste_termines.addItem(self.item)
        self.item = None

##    def rechercher_par_titre(self):
##        print("tu as voulus rechercher par titre")

##    def rechercher_par_genre(self):
##        print("nan mais ça c'est pas codé encore")

    def telecharger_les_liens(self):
        global ficheInfos
        thread_dl.run()
        liste_selection = self.liste_liens.selectedItems()
        #liste_selection.sort()
        nb_episode = len(ficheInfos['episodes'])
        for item in liste_selection:
            if self.liste_liens.row(item) < nb_episode:
                ficheInfos['episodes'][self.liste_liens.row(item)]['id_anime'] = ficheInfos['id']
                if thread_dl.add_dl(ficheInfos['episodes'][self.liste_liens.row(item)]) :
                    text = ''.join([ficheInfos['titre'], " ( " , QtGui.QListWidgetItem(item).text()," )"])
                    self.liste_en_attente.insertItem(0,text)
                
                
    
            else:
                ficheInfos['bonus'][self.liste_liens.row(item) - nb_episode]['id_anime'] = ficheInfos['id']
                if thread_dl.add_dl(ficheInfos['bonus'][self.liste_liens.row(item) - nb_episode]) :
                    text = ''.join([ficheInfos['titre'], " ( " , QtGui.QListWidgetItem(item).text()," )"])
                    self.liste_en_attente.insertItem(0,text)
        self.liste_liens.clearSelection()  
            
                
##    def a_propos(self):
##        print("là ça va être moins dur mais quand même")

    def newValueToBar(self, value):
        self.avancement_en_cours.setValue(value)

    def monter_dl(self):
        sel = self.liste_en_attente.currentRow()
        indice = self.liste_en_attente.count() - sel
        if indice>1:
            element = self.liste_en_attente.takeItem(sel)
            item = thread_dl.liste_dl.pop(indice-1)
            self.liste_en_attente.insertItem(sel+1,element)
            thread_dl.liste_dl.insert(indice-2,item)
            self.liste_en_attente.setCurrentRow(sel+1)

	
    def descendre_dl(self):
        sel = self.liste_en_attente.currentRow()
        indice = self.liste_en_attente.count() - sel
        if indice < self.liste_en_attente.count():
            element = self.liste_en_attente.takeItem(sel)
            item = thread_dl.liste_dl.pop(indice-1)
            self.liste_en_attente.insertItem(sel-1,element)
            thread_dl.liste_dl.insert(indice,item)
            self.liste_en_attente.setCurrentRow(sel-1)
        
        
    def retranslateUi(self, Fenetre_principale):
        Fenetre_principale.setWindowTitle(QtGui.QApplication.translate("Fenetre_principale", "Otaku-Loader ( Qt )", None, QtGui.QApplication.UnicodeUTF8))
        self.Titre.setText(QtGui.QApplication.translate("Fenetre_principale", "Titre :", None, QtGui.QApplication.UnicodeUTF8))
        self.download_it.setText(QtGui.QApplication.translate("Fenetre_principale", "Télécharger les épisodes séléctionnés", None, QtGui.QApplication.UnicodeUTF8))
        self.Image.setText(QtGui.QApplication.translate("Fenetre_principale", "Image", None, QtGui.QApplication.UnicodeUTF8))
        self.Genre.setText(QtGui.QApplication.translate("Fenetre_principale", "Genre :", None, QtGui.QApplication.UnicodeUTF8))
        self.les_onglets.setTabText(self.les_onglets.indexOf(self.first_page), QtGui.QApplication.translate("Fenetre_principale", "Liste des animés", None, QtGui.QApplication.UnicodeUTF8))
        self.Termines.setText(QtGui.QApplication.translate("Fenetre_principale", "Terminés", None, QtGui.QApplication.UnicodeUTF8))
        self.avancement_en_cours.setFormat(QtGui.QApplication.translate("Fenetre_principale", "%p%", None, QtGui.QApplication.UnicodeUTF8))
        self.taille_en_cours.setText(QtGui.QApplication.translate("Fenetre_principale", "Taille : ", None, QtGui.QApplication.UnicodeUTF8))
        self.titre_en_cours.setText(QtGui.QApplication.translate("Fenetre_principale", "Titre de l\'épisode : ", None, QtGui.QApplication.UnicodeUTF8))
        self.En_cours.setText(QtGui.QApplication.translate("Fenetre_principale", "En cours", None, QtGui.QApplication.UnicodeUTF8))
        self.Enattente.setText(QtGui.QApplication.translate("Fenetre_principale", "En attente", None, QtGui.QApplication.UnicodeUTF8))
        self.monter_button.setText(QtGui.QApplication.translate("Fenetre_principale", "Monter", None, QtGui.QApplication.UnicodeUTF8))
        self.pause_button.setText(QtGui.QApplication.translate("Fenetre_principale", "Mettre en pause", None, QtGui.QApplication.UnicodeUTF8))
        self.descendre_button.setText(QtGui.QApplication.translate("Fenetre_principale", "Descendre", None, QtGui.QApplication.UnicodeUTF8))
        self.les_onglets.setTabText(self.les_onglets.indexOf(self.second_page), QtGui.QApplication.translate("Fenetre_principale", "Téléchargements", None, QtGui.QApplication.UnicodeUTF8))
        self.menu_Fichier.setTitle(QtGui.QApplication.translate("Fenetre_principale", "&Fichier", None, QtGui.QApplication.UnicodeUTF8))
        self.menu_Edition.setTitle(QtGui.QApplication.translate("Fenetre_principale", "&Edition", None, QtGui.QApplication.UnicodeUTF8))
        self.menuRechercher.setTitle(QtGui.QApplication.translate("Fenetre_principale", "Rechercher", None, QtGui.QApplication.UnicodeUTF8))
        self.menu.setTitle(QtGui.QApplication.translate("Fenetre_principale", "?", None, QtGui.QApplication.UnicodeUTF8))
        self.action_R_cup_rer_la_liste.setText(QtGui.QApplication.translate("Fenetre_principale", "Récupérer la liste", None, QtGui.QApplication.UnicodeUTF8))
        self.action_Charger_la_liste.setText(QtGui.QApplication.translate("Fenetre_principale", "Charger la liste", None, QtGui.QApplication.UnicodeUTF8))
        self.action_Reg_n_rer_le_cache.setText(QtGui.QApplication.translate("Fenetre_principale", "Regénérer le cache", None, QtGui.QApplication.UnicodeUTF8))
        self.action_T_l_charger_les_liens.setText(QtGui.QApplication.translate("Fenetre_principale", "Télécharger les épisodes séléctionnés", None, QtGui.QApplication.UnicodeUTF8))
        self.action_A_propos.setText(QtGui.QApplication.translate("Fenetre_principale", "A propos", None, QtGui.QApplication.UnicodeUTF8))
        self.actionPar_titre.setText(QtGui.QApplication.translate("Fenetre_principale", "Par titre", None, QtGui.QApplication.UnicodeUTF8))
        self.actionPar_genre.setText(QtGui.QApplication.translate("Fenetre_principale", "Par genre", None, QtGui.QApplication.UnicodeUTF8))
